package com.trendata.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.trendata.service.CacheService;
import com.trendata.util.JsonResult;
import com.trendata.util.TimeUtil;

/**
 * 缓存管理
 * 
 * @author: HuangXiuXiu Email:243559392@qq.com
 */
@Controller
@RequestMapping("/cache")
public class CacheController {

	@Autowired
	private CacheService cacheService;

	/**
	 * 
	 * 清除accessToken缓存
	 * <p>
	 * url=/cache/removeAccessToken.do
	 * </p>
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/removeAccessToken")
	@ResponseBody
	public String removeAccessToken(HttpServletRequest request, HttpServletResponse response) {
		JsonResult result = new JsonResult();
		cacheService.removeAccessToken(TimeUtil.getCurrentHour());
		result.setSuccess(true);
		return result.toJsonString();
	}

	/**
	 * 清楚jsTicket缓存
	 * <p>
	 * url = cache/removeJSTicket.do
	 * </p>
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/removeJSTicket")
	@ResponseBody
	public String removeJSTicket(HttpServletRequest request, HttpServletResponse response) {
		JsonResult result = new JsonResult();
		cacheService.removeJSTicket(TimeUtil.getCurrentHour());
		result.setSuccess(true);
		return result.toJsonString();
	}

}
